< previous page page_710 next page >

Page 710
0710-01.jpg
Figure 31.6
The Server variable 
HTTP_USER_AGENT
allows you to determine a user's browser type.
The Server Object
The primary use of the ASP Server object is to create objects on the Web server so your ASP application can access them. You have already seen how to create an ADO connection object:
Set cn = Server.CreateObject("ADODB.Connection")
You can also create objects from classes that you compile into an ActiveX DLL, as you will see shortly.
As an alternative to the Server.CreateObject statement, you can embed an <OBJECT> tag in your ASP file with the RUNAT option set to Server:
<OBJECT RUNAT="Server" ID=cn PROGID="ADODB.Connection"></OBJECT>
Either syntax creates an ADODB.Connection object on the Web server. However, the <OBJECT> tag cannot be used inside the script tags.
The Application Object and GLOBAL.ASA
Earlier in this chapter, you discovered how the directory layout is used to identify ASP applications. This is important if you want to program the Start and End events associated with applications and sessions. To write procedure code for these events, you place a special file called GLOBAL.ASA in the ASP application's root directory. The GLOBAL.ASA can contain code for these events, as in the following example:
Sub Session_OnStart()
   Dim x
   Set x = Server.CreateObject("ADODB.Connection")
   Set Session("CONNECTION") = x

End Sub
You can use the GLOBAL.ASA file to add a Web page hit counter, close and open databases, or any other activity that needs to occur when a user starts and exits your application.

 
< previous page page_710 next page >